//
//  TabBarViewController.m
//  TheOne
//
//  Created by lanou3g on 16/3/10.
//  Copyright © 2016年 Wicky. All rights reserved.
//

#import "TabBarViewController.h"
#import "HomeViewController.h"
#import "ReadViewController.h"
#import "MusicViewController.h"
#import "MovieViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView * backV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 49)];
    backV.backgroundColor = [UIColor whiteColor];
    [self.tabBar insertSubview:backV atIndex:0];
    HomeViewController *home = [[HomeViewController alloc]init];
    [self addChildVc:home title:@"首页" Image:@"tab_home_default~iphone" selectedImage:@"tab_home_selected~iphone"];
    
    MusicViewController  *music = [[MusicViewController alloc] init];
    [self addChildVc:music title:@"音乐" Image:@"tab_music_default~iphone" selectedImage:@"tab_music_selected~iphone"];
    
    ReadViewController *read = [[ReadViewController alloc]init];
    [self addChildVc:read title:@"阅读" Image:@"tab_reading_default~iphone" selectedImage:@"tab_reading_selected~iphone"];
    
    MovieViewController *movie = [[MovieViewController alloc] init];
    [self addChildVc:movie title:@"电影" Image:@"tab_movie_default~iphone" selectedImage:@"tab_movie_selected~iphone"];
}

- (void)addChildVc:(UIViewController *)ChildVc title:(NSString *)title Image:(NSString*)image selectedImage:(NSString *)selectedImage
{
    ChildVc.title = title;
    ChildVc.tabBarItem.title = title;
    ChildVc.tabBarItem.image = [UIImage imageNamed:image];
    ChildVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
 
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = HWColor(123, 123, 123);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = HWColor(118, 152, 208);
    [ChildVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [ChildVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    
    //给控制器添加一个导航栏
    UINavigationController * root = [[UINavigationController alloc]initWithRootViewController:ChildVc];
    root.navigationBar.barTintColor = [UIColor whiteColor];
    ChildVc.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_me_default~iphone"] style:UIBarButtonItemStyleDone target:self action:@selector(rightAction)];
    //添加子控制
    [self addChildViewController:root];

}

- (void)rightAction
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
